package com.legna.mhxy.support.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.legna.mhxy.support.common.SupportException;
import com.legna.mhxy.support.dao.UserDao;
import com.legna.mhxy.support.entity.User;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


@Service
@Slf4j
@AllArgsConstructor
public class LoginService {
    private final UserDao userDao;


    public User login(String login, String pwd) {
        User user = userDao.selectOne(new LambdaQueryWrapper<User>().eq(User::getLogin, login).last("limit 1"));
        if (user == null){
            throw new SupportException("账号不存在");
        }
        if (!user.getPwd().equals(pwd)){
            throw new SupportException("密码错误");
        }
        user.setPwd(null);
        return user;
    }
}
